package com.share.dubbo.wssh;

import com.share.common.utils.IpUtil;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.web.context.support.WebApplicationContextUtils;
import org.springframework.web.context.support.XmlWebApplicationContext;

import javax.servlet.http.HttpServletRequest;

/**
 * @author 01401061 - 孙艳强
 * @date 2020/10/27 18:09
 */
/*引入Apache的enable*/
@Slf4j
@EnableDubbo(scanBasePackages = {"com.share.dubbo.wssh.service", "com.share.dubbo.es.service", "com.share.dubbo.ssm.service"})
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class},
        scanBasePackages = {"com.share.dubbo.wssh","com.share.dubbo.es","com.share.dubbo.ssm"})
public class AppWssh {
    static {
        String ip = IpUtil.getIp();
        System.setProperty("dubbo.protocol.host", ip);
        System.setProperty("DUBBO_IP_TO_REGISTRY", ip);
        System.setProperty("DUBBO_IP_TO_BIND", ip);
        log.info("把ip设置到dubbo.protocol.host系统参数中,ip={}", ip);
    }

    public static void main(String[] args) {
        SpringApplication.run(AppWssh.class, args);
    }

    @ApiOperation("刷新配置-依赖context.support")
    public void refresh(HttpServletRequest request) {
        XmlWebApplicationContext context = (XmlWebApplicationContext) WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
        context.refresh();
    }
}
